package org.duang.plugins;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.duang.token.ITokenCache;
import org.duang.token.Token;
import org.duang.token.TokenManager;


public class TokenPlugin implements IPlugin {

	
	public void start() throws Exception{
		TokenManager.init(new FastTokenCache());
	}

	public void stop() throws Exception{
		TokenManager.removeAllToken();
	}

}

class FastTokenCache implements ITokenCache{

	List<Token> tokenList = new ArrayList<Token>();
	
	@Override
	public boolean contains(Token token) {
		for(Iterator<Token> it =  tokenList.iterator(); it.hasNext();){
			if(it.next().equals(token)){
				return true;
			}
		}
		return false;
//		return tokenList.contains(token);
	}

	@Override
	public List<Token> getAll() {
		return tokenList;
	}

	@Override
	public void put(Token token) {
		tokenList.add(token);
	}

	@Override
	public void remove(Token token) {
		tokenList.remove(token);
		
	}
	
}
